package com.starblink.login.editpersonalinfo.ui

import android.view.View
import androidx.core.os.bundleOf
import androidx.fragment.app.setFragmentResult
import com.luck.picture.lib.basic.PictureSelector
import com.luck.picture.lib.config.PictureMimeType
import com.luck.picture.lib.config.SelectMimeType
import com.luck.picture.lib.config.SelectModeConfig
import com.luck.picture.lib.entity.LocalMedia
import com.luck.picture.lib.interfaces.OnResultCallbackListener
import com.starblink.android.basic.ext.click
import com.starblink.android.basic.widget.dialog.BaseBottomSheetFragment
import com.starblink.basic.log.SKLogger
import com.starblink.login.databinding.DialogSelectGetPictureModeBinding

/**
 * 选择获取图片方式弹窗（拍照或从相册获取）
 */
class SelectGetPictureModeDialog : BaseBottomSheetFragment() {

    lateinit var viewBinding: DialogSelectGetPictureModeBinding

    override fun getBindingRootView(): View {
        viewBinding = DialogSelectGetPictureModeBinding.inflate(layoutInflater)
        return viewBinding.root
    }

    override fun initView() {
        // 使用系统相机拍照
        viewBinding.tvTakePhoto.click {
            setFragmentResult(
                REQUEST_KEY_GET_PICTURE_MODE,
                bundleOf(BUNDLE_KEY_GET_PICTURE_MODE to GET_PICTURE_MODE_TAKE_PICTURE)
            )
            dismiss()
        }

        // 从系统相册选择
        viewBinding.tvImageSelect.click {
            setFragmentResult(
                REQUEST_KEY_GET_PICTURE_MODE,
                bundleOf(BUNDLE_KEY_GET_PICTURE_MODE to GET_PICTURE_MODE_SYSTEM_GALLERY)
            )
            dismiss()
        }

        viewBinding.tvCancel.click {
            dismiss()
        }
    }

    companion object {
        const val REQUEST_KEY_GET_PICTURE_MODE = "REQUEST_KEY_GET_PICTURE_MODE"
        const val BUNDLE_KEY_GET_PICTURE_MODE = "BUNDLE_KEY_GET_PICTURE_MODE"

        const val GET_PICTURE_MODE_TAKE_PICTURE = 1  //拍照获取图片
        const val GET_PICTURE_MODE_SYSTEM_GALLERY = 2 //从系统图册获取图片
    }
}